﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SM2TestRunner;

namespace SM2RegressionBugVerificationV5
{
    public class LaunchTesting
    {
        public static void LaunchSandbox()
        {
            string strListItemsFile = Repository.ID1433.getAllSandBoxes("JimSandboxes");
            string[] listEntriesFromFile = strListItemsFile.Split(','); int intLength_listEntriesFromFile = listEntriesFromFile.Length;
            for (int iFile = 0; iFile < intLength_listEntriesFromFile; iFile++)
            {
                string strSandboxName = listEntriesFromFile[iFile];
                string strURL = "http://sm2.techrigy.com/" + strSandboxName;
                
                if (!strSandboxName.Equals(""))
                {
                    try
                    {
                        Utilities.GlobalObject.MANAGER.ActiveBrowser.NavigateTo(strURL);
                        Utilities.GlobalObject.MANAGER.ActiveBrowser.WaitUntilReady();
                        System.Threading.Thread.Sleep(1);

                        if (Utilities.GlobalObject.MANAGER.ActiveBrowser.ContainsText("Email")
                            && Utilities.GlobalObject.MANAGER.ActiveBrowser.ContainsText("Password"))
                        {
                            Utilities.GlobalObject.LOGGER.log(strURL + " > PASSED");
                            System.Threading.Thread.Sleep(1);
                        }
                        else
                        {
                            Utilities.GlobalObject.LOGGER.log(strURL + " > FAILED");
                        }
                    }
                    catch 
                    {
                        try
                        {    

                            while ((!Utilities.GlobalObject.MANAGER.ActiveBrowser.ContainsText("Email"))
                                || (!Utilities.GlobalObject.MANAGER.ActiveBrowser.ContainsText("Password")))
                            {
                                System.Threading.Thread.Sleep(1000);
                            }
                            Utilities.GlobalObject.LOGGER.log(strURL + " > PASSED");
                            System.Threading.Thread.Sleep(1);
                        }
                        catch
                        {
                            Utilities.GlobalObject.LOGGER.log(strURL + " > FAILED");
                        }
                    }
                }
            }            
        }
    }
}